/*
 * hmc5883l.h
 *
 *  Created on: Jan 11, 2014
 *      Author: bohni
 */

#ifndef HMC5883L_H_
#define HMC5883L_H_

#include "software_i2c_master.h"
#include "c_g_module_config.h"

#include <avr/eeprom.h>
#include <util/delay.h>

//////////////////////////////////////////////////////
// HMC5883L Registers

#define CONFIG_REG_A 		0x00
#define CONFIG_REG_B 		0x01
#define MODE_REG	 		0x02
#define DATA_OUT_X_MSB	 	0x03
#define DATA_OUT_X_LSB		0x04
#define DATA_OUT_Z_MSB		0x05
#define DATA_OUT_Z_LSB		0x06
#define DATA_OUT_Y_MSB 		0x07
#define DATA_OUT_Y_LSB		0x08
#define STATUS_REG	 		0x09
#define IDENTIFICATION_A 	0x0A
#define IDENTIFICATION_B	0x0B
#define IDENTIFICATION_C 	0x0C

/////////////////////////////////////////////////////////

#define HMC5883L_READ_ADR  	0x3D
#define HMC5883L_WRITE_ADR  0x3C

/////////////////////////////////////////////////////////

struct magnet_values {

	int16_t out_x;
	int16_t out_y;
	int16_t out_z;

};

extern struct magnet_values magnet;

extern int16_t compass; // angle between device/north

void hmc5883l_init();

void hmc5883l_read_values();

void compute_north();

void hmc5883l_self_test();

void hmc5883l_temp_compensation();

void hmc5883l_write_reg ( uint8_t adr, uint8_t data);

uint8_t hmc5883l_read_reg ( uint8_t adr);

#endif /* HMC5883L_H_ */
